//
// Created by xbm on 23-3-9.
//

#ifndef WEBSERVER_THREADPOOL_H
#define WEBSERVER_THREADPOOL_H

#include <thread>
#include <vector>
#include <future>
#include "nonCopyable.h"
#include "worker.h"

using namespace std;

namespace threadPool {
class ThreadPool : util::NonCopyable {
public:
    using JOB_TYPE = Worker::JOB_TYPE;

    static ThreadPool &getInstance() {
        static ThreadPool p;
        return p;
    }
    void init(int capacity = 4);

    void close();

    future<void> commit(JOB_TYPE job);

private:
    ThreadPool();

    ~ThreadPool();
    bool done_= false;
    int capacity_=0;
};
}
#endif //WEBSERVER_THREADPOOL_H
